Interactivity in R with JS

Bi[R]mingham R

February 24, 2015

Interactivity in R

  • Wading into a pool of promise littered with “failure”

  • ubiquity + innovation of web -> promise within reach

  • Will limit this discussion of interactivity to R + JS/HTML

How to Get JS -> R

How to Get R <-> JS

V8

Not really interactive, but why rewrite good code?

library(V8)

ct <- new_context( "window" )
ct$eval ( 
  " console.log( ['I am in JavaScript. 1+1 = ', 1 + 1].join('') ) "
)
## I am in JavaScript. 1+1 = 2

V8 (more powerful examples)

geospatial analysis with Turf.js

pdf creation with libharu

SQLite

Manually

<div id = "manual-example"></div>
<script>
  document.getElementById("manual-example")
    .innerText = "ugly manual example"
</script>

htmlwidgets

Use JavaScript without knowing any JavaScript

htmlwidgets - Leaflet

library(leaflet)
m = leaflet( width = 400, height = 400) %>% addTiles()
htmlwidgets::as.iframe(
  m %>% setView( -86.8034743, 33.5025432, zoom=17 )
  ,height = 500
)

htmlwidgets - rpivotTable

library(rpivotTable)

rpivotTable( data.frame(Titanic) )

htmlwidgets - qtlcharts

library(qtlcharts)
data(geneExpr)
iplotCorr( geneExpr$expr, geneExpr$genotype, reorder=TRUE
   ,chartOpts=list( height = 400, width = 800 )
)

htmlwidgets - svgPanZoom

library(SVGAnnotation)
library(svgPanZoom)
svgPanZoom(
  svgPlot(image(volcano), height = 400, width = 400)
  ,controlIconsEnabled = T
)

htmlwidgets - epiwidgets

library(epiwidgets)
library(ape)
data(bird.orders)
treewidget(bird.orders,height = 400, width = 800)

Questions ???

Other Resources